package com.xuyy.exportword.exception;

import freemarker.core.Environment;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;

import java.io.IOException;
import java.io.Writer;

/**
 * Created with IntelliJ IDEA.
 * User: liangme
 * Date: 2018/4/2
 * Time: 11:28
 */
public class MyTemplateExceptionHandler implements TemplateExceptionHandler{
    @Override
    public void handleTemplateException(TemplateException te, Environment env, Writer out) throws TemplateException {
        try {
            System.out.println("[错误信息: " + te.getMessage() + "]0.0");
            out.write("[错误信息: " + te.getMessage() + "]0.0");
        } catch (IOException e) {
            throw new TemplateException("Failed to print error message. Cause: " + e, env);
        }
    }
}
